# regression (only treatment)
# 20200414

# example
# Bessei question 1 
source("diff_mean_pretest_functions.R")

# load data
data <- read.csv("data.csv")
treat <- read.csv("treat.csv")

# surname -------------------------------------------------------------------



# questions
q_surname1 <- c("surname_1_intl", "surname_1_const", "surname_1_ngo", "surname_1_control")
q_surname2 <- c("surname_2_intl", "surname_2_const", "surname_2_ngo", "surname_2_control")
q_surname3 <- c("surname_3_intl", "surname_3_const", "surname_3_ngo", "surname_3_control")

#difference in means
surname1_dm <- diff_mean(data=data, treat=treat, questions=q_surname1)
surname2_dm <- diff_mean(data=data, treat=treat, questions=q_surname2)
surname3_dm <- diff_mean(data=data, treat=treat, questions=q_surname3)

# plot
png("marriage.png")
plot(x=seq(1,11),
     xaxt="n", 
     y=c(surname1_dm$point, NA, surname2_dm$point, NA, surname3_dm$point),
     ylim=c(-0.5, 0.5),
     ylab="treatment effect",
     #xlab=xlabel,
     xlab="",
     main=paste0("Mixed-surname Marriage"))
abline(h=0, col="red")
segments(x0=seq(1,11),
         y0=c(surname1_dm$lower, NA, surname2_dm$lower, NA, surname3_dm$lower),
         y1=c(surname1_dm$upper, NA, surname2_dm$upper, NA, surname3_dm$upper))
axis(side=1, at=c(1,2,3,5,6,7,9,10,11),
     labels=rep(c("T1", "T2", "T3"), 3),
     las=1, cex.axis=1)
axis(side=1, at=c(2,6,10),
     labels=c("Own choice", "Others' choice", "System"),
     line=2, lwd=0)
dev.off()


# wage gap -------------------------------------------------------------------

q_wage1 <- c("wage_1_intl", "wage_1_const", "wage_1_ngo", "wage_1_control")
q_wage2 <- c("wage_2_intl", "wage_2_const", "wage_2_ngo", "wage_2_control")

wage1_dm <- diff_mean(data=data, treat=treat, questions=q_wage1)
wage2_dm <- diff_mean(data=data, treat=treat, questions=q_wage2)


png("wage.png")
plot(x=seq(1,7),
     xaxt="n", 
     y=c(wage1_dm$point, NA, wage2_dm$point),
     ylim=c(-0.2, 0.8),
     ylab="treatment effect",
     xlab="",
     main=paste0("Gender Wage Gap"))
abline(h=0, col="red")
segments(x0=seq(1,11),
         y0=c(wage1_dm$lower, NA, wage2_dm$lower),
         y1=c(wage1_dm$upper, NA, wage2_dm$upper, NA))
axis(side=1, at=c(1,2,3,5,6,7),
     labels=rep(c("T1", "T2", "T3"), 2),
     las=1, cex.axis=1)
axis(side=1, at=c(2,6),
     labels=c("Recognition of wage gap", "Policy"),
     line=2, lwd=0)
dev.off()

## whaling ---------------------------------------------------------------------

q_whale1 <- c("whale_1_intl", "whale_1_const", "whale_1_ngo", "whale_1_control")
q_whale2 <- c("whale_2_intl", "whale_2_const", "whale_2_ngo", "whale_2_control")

whale1_dm <- diff_mean(data=data, treat=treat, questions=q_whale1)
whale2_dm <- diff_mean(data=data, treat=treat, questions=q_whale2)

png("whale.png")
plot(x=seq(1,7),
     xaxt="n", 
     y=c(whale1_dm$point, NA, whale2_dm$point),
     ylim=c(-0.5, 0.5),
     ylab="treatment effect",
     xlab="",
     main=paste0("Whaling"))
abline(h=0, col="red")
segments(x0=seq(1,11),
         y0=c(whale1_dm$lower, NA, whale2_dm$lower),
         y1=c(whale1_dm$upper, NA, whale2_dm$upper, NA))
axis(side=1, at=c(1,2,3,5,6,7),
     labels=rep(c("T1", "T2", "T3"), 2),
     las=1, cex.axis=1)
axis(side=1, at=c(2,6),
     labels=c("Whaling", "Whale meat"),
     line=2, lwd=0)
dev.off()


## hate speech ---------------------------------------------------------------
q_hate1 <- c("hate_1_intl", "hate_1_const", "hate_1_ngo", "hate_1_control")

hate_dm <- diff_mean(data=data, treat=treat, questions=q_hate1)

png("hate.png")
plot(x=seq(1,5),
     xaxt="n", 
     y=c(NA, hate_dm$point, NA),
     ylim=c(-0.5, 0.5),
     ylab="treatment effect",
     xlab="",
     main=paste0("Hate Speech"))
abline(h=0, col="red")
segments(x0=seq(2,4),
         y0=c(hate_dm$lower),
         y1=c(hate_dm$upper))
axis(side=1, at=c(2,3,4),
     labels=rep(c("T1", "T2", "T3"), 1),
     las=1, cex.axis=1)
dev.off()

## death penalty ---------------------------------------------------------
q_death1 <- c("death_1_intl", "death_1_const", "death_1_ngo", "death_1_control")
death_dm <- diff_mean(data=data, treat=treat, questions=q_death1)

png("death.png")
plot(x=seq(1,5),
     xaxt="n", 
     y=c(NA, death_dm$point, NA),
     ylim=c(-0.5, 0.5),
     ylab="treatment effect",
     xlab="",
     main=paste0("Death Penalty"))
abline(h=0, col="red")
segments(x0=seq(2,4),
         y0=c(death_dm$lower),
         y1=c(death_dm$upper))
axis(side=1, at=c(2,3,4),
     labels=rep(c("T1", "T2", "T3"), 1),
     las=1, cex.axis=1)
dev.off()


